<template>
  <div>
    <div class="abs" v-show="flag"><router-link tab='div' to='/' class="iconfont header_back_iconfot">&#xe624;</router-link></div>
    <div class="detail_header" v-show="!flag" :style="opacity">
      景点详情
      <router-link to="/">
       <div class="iconfont detail_header_back_index">&#xe624;</div>
      </router-link>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      flag: true,
      opacity: 0
    }
  },
  methods: {
    handelScroll () {
      const top = document.documentElement.scrollTop
      if (top > 60) {
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacity = { opacity }
        this.flag = false
      } else {
        this.flag = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handelScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handelScroll)
  }
}
</script>

<style lang="stylus" scoped>
 @import '~styles/varibles.styl'
 .abs
  line-height .8rem
  position absolute
  top 0
  left 0
  width .8rem
  height .8rem
  text-align center
  border-radius .4rem
  background rgba(0, 0, 0, .8)
  .header_back_iconfot
   color #fff
   font-size .4rem
 .detail_header
  height $headerHeight
  line-height $headerHeight
  text-align center
  color #fff
  background $bgColor
  font-size .32rem
  position fixed
  top 0
  left 0
  right 0
  z-index 2
  .detail_header_back_index
    color: #ffffff
    font-size .4rem
    position absolute
    left 0
    top 0
    width .64rem
    text-align center
</style>
